<template>
  <a-spin :spinning="isLoading" tip="转换中">
    <video :src="imgSrc" data-w="170" importance="high" />
  </a-spin>
</template>
<script setup>
import { ref } from 'vue'
import { isCR3 } from 'utils/utils.js'
// import { downloadBlob } from 'utils/file.js'
import { libraryManagement_cr3_convert_post_ } from 'server/apis/7147.js'
const props = defineProps({
  src: {
    type: String,
    default: ''
  },
  type: {
    type: String,
    default: 'image/png'
  }
})
const imgSrc = ref('')
const isLoading = ref(false)
const toConvert = async () => {
  isLoading.value = true
  if (isCR3(props.src)) {
    libraryManagement_cr3_convert_post_(
      {
        url: props.src
      },
      data => {
        // downloadBlob(data, '98888', 'image/jpeg')
        // const oFileReader = new FileReader()
        // const img = new Image()
        // img.onload = a => {
        //   console.log(a)
        //   debugger
        // }
        // oFileReader.onloadend = function (e) {
        //   if (e.target) {
        //     const base64 = e.target.result
        //     debugger
        //     imgSrc.value = base64.replace(/\s/g, '')
        //   }
        // }
        // oFileReader.readAsDataURL(data)

        imgSrc.value = window.URL.createObjectURL(
          new Blob([
            data,
            {
              type: 'image/jpeg'
            }
          ])
        )
      },
      {
        closeLoading() {
          isLoading.value = false
        }
      }
    )
  }
}
props.src && toConvert()
</script>
<style lang="scss" scoped></style>
